define(['backbone', 'backboneLocalstorage', '../models/todo'],function(Backbone, Store, Todo){
  var Todos = Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store('todos-backbone'),
    completed: function(){
      return this.filter(function( todo ){
        return todo.get('completed');
      })
    },
    remaining: function(){
      return this.without.apply(this, this.completed());
    },
    nextOrder: function(){
      if(!this.length) {
        return 1;
      }
      return this.last().get('order') + 1;
    }
  });
  return new Todos();
})